package com.eascs.workflow.massSms.controller;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.common.service.ILoanInfoService;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.tag.MenuTag;
import com.eascs.workflow.common.controller.BaseMasterViewController;
import com.eascs.workflow.massSms.service.IMassSmsService;
import com.eascs.workflow.massSms.vo.MassSmsVo;

@Controller
@RequestMapping("/massSms")
public class MassSmsController extends BaseMasterViewController {

	@Inject
	IMassSmsService iMassSmsService;

	
	
	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "massSms");
	}

	@RequestMapping("/list")
	public String smsList(MassSmsVo vo) {
		vo.setPageSize(10);
		String pageUrl = "/massSms/list";
		if (vo != null) {
			pageUrl = UrlUtil.appendUrl(pageUrl, "bizCode", vo.getBizCode() == null ? "" : vo.getBizCode());
			pageUrl = UrlUtil.appendUrl(pageUrl, "status", vo.getStatus() == null ? "" : vo.getStatus());// 0未发送1发送
			pageUrl = UrlUtil.appendUrl(pageUrl, "remark", vo.getRemark() == null ? "" : vo.getRemark());
			pageUrl = UrlUtil.appendUrl(pageUrl, "sendType", vo.getSendType() == null ? "" : vo.getSendType());// IMM及时发送
																												// TIM定时发送
			pageUrl = UrlUtil.appendUrl(pageUrl, "creator", vo.getCreator() == null ? "" : vo.getCreator());
			pageUrl = UrlUtil.appendUrl(pageUrl, "content", vo.getContent() == null ? "" : vo.getContent());
			pageUrl = UrlUtil.appendUrl(pageUrl, "beginDate", vo.getBeginDate() == null ? "" : vo.getBeginDate());
			pageUrl = UrlUtil.appendUrl(pageUrl, "endDate", vo.getEndDate() == null ? "" : vo.getEndDate());
			pageUrl = pageUrl + "&pageIndex=";
		} else {
			pageUrl = pageUrl + "?pageIndex=";
		}

		String titles[] = { "单号", "接收号码", "发送类型", "创建人", "创建时间", "发送状态" };
		SelectDataOption[] selectDataOptions = { null, null, new SelectDataOption("sendType"), null, null,
				new SelectDataOption("sendStatus") };
		PageResult<Object[]> pageResult = iMassSmsService.getSmsList(vo);
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl);
		Button[] titleButtons = new Button[] { ButtonHelper.createAjaxButton(null, "/massSmsRest/detail?requestId=") };
		paginationInfo.setTitleButtons(titleButtons);
		paginationInfo.setSelectDataOptions(selectDataOptions);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setBuildPagingNavigation(true);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", vo);
		return "massSms/list";
	}

}
